home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 101-125 / disk_107 / prosuite / fileio / main.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  6KB  |  236 lines

  1.  
  2. /* *** main.c ***************************************************************
  3.  *
  4.  * File IO Suite  --  Example Main 
  5.  *     from Book 1 of the Amiga Programmers' Suite by RJ Mical
  6.  *
  7.  * Copyright (C) 1986, 1987, Robert J. Mical
  8.  * All Rights Reserved.
  9.  *
  10.  * Created for Amiga developers.
  11.  * Any or all of this code can be used in any program as long as this
  12.  * entire copyright notice is retained, ok?
  13.  *
  14.  * The Amiga Programmer's Suite Book 1 is copyrighted but freely distributable.
  15.  * All copyright notices and all file headers must be retained intact.
  16.  * The Amiga Programmer's Suite Book 1 may be compiled and assembled, and the 
  17.  * resultant object code may be included in any software product.  However, no 
  18.  * portion of the source listings or documentation of the Amiga Programmer's 
  19.  * Suite Book 1 may be distributed or sold for profit or in a for-profit 
  20.  * product without the written authorization of the author, RJ Mical.
  21.  * 
  22.  * HISTORY      NAME            DESCRIPTION
  23.  * -----------  --------------  --------------------------------------------
  24.  * 4 Feb 87     RJ              Real release
  25.  * 12 Aug 86    RJ >:-{)*       Prepare (clean house) for release
  26.  * 3 May 86     =RJ Mical=      Fix prop gadget for both 1.1 and 1.2
  27.  * 1 Feb 86     =RJ Mical=      Created this file.
  28.  *
  29.  * *********************************************************************** */
  30.  
  31.  
  32. #define FILEIO_SOURCEFILE
  33. #include "fileio.h"
  34.  
  35.  
  36. BOOL TestFileIO();
  37.  
  38.  
  39. struct NewScreen NewFileIOScreen =
  40.     {
  41.     0, 0,    /* LeftEdge, TopEdge */
  42.     320, 200, /* Width, Height */
  43.     2, /* Depth */
  44.     0, 1,    /* Detail/BlockPens */
  45.     NULL,    /* ViewPort Modes (must set/clear HIRES as needed) */
  46.     CUSTOMSCREEN,
  47.     &SafeFont,    /* Font */
  48.     (UBYTE *)"Example FileIO Program's Screen",
  49.     NULL,    /* Gadgets */
  50.     NULL,    /* CustomBitMap */
  51.     };
  52.  
  53. struct NewWindow NewFileIOWindow =
  54.     {
  55.     0, 12,                    /* LeftEdge, TopEdge */
  56.     320, 150,             /* Width, Height */
  57.     -1, -1,                /* Detail/BlockPens */
  58.     NEWSIZE | MOUSEBUTTONS | VANILLAKEY | MENUPICK | CLOSEWINDOW
  59.             | DISKINSERTED,
  60.                             /* IDCMP Flags */
  61.     WINDOWSIZING | WINDOWDRAG | WINDOWDEPTH | WINDOWCLOSE
  62.             | SIZEBRIGHT | SMART_REFRESH | RMBTRAP | ACTIVATE | NOCAREREFRESH,
  63.                             /* Window Specification Flags */
  64.     NULL,                    /* FirstGadget */
  65.     NULL,                    /* Checkmark */
  66.     (UBYTE *)"FileIO Requester Window",  /* WindowTitle */
  67.     NULL,                    /* Screen */
  68.     NULL,                    /* SuperBitMap */
  69.     96, 30,                /* MinWidth, MinHeight */
  70.     640, 200,            /* MaxWidth, MaxHeight */
  71.     WBENCHSCREEN,
  72.     };
  73.  
  74.  
  75.  
  76. VOID main(argc, argv)
  77. LONG argc;
  78. char **argv;
  79. {
  80.     struct Screen *screen;
  81.     struct Window *window;
  82.     struct FileIOSupport *fileio1, *fileio2;
  83.     BOOL mainswitch, ioswitch, mainsuccess;
  84.     LONG class;
  85.     struct IntuiMessage *message;
  86.     SHORT pick;
  87.  
  88.     mainsuccess = FALSE;
  89.  
  90.     screen = NULL;
  91.     window = NULL;
  92.     fileio1 = fileio2 = NULL;
  93.  
  94.     IntuitionBase = (struct IntuitionBase *)
  95.             OpenLibrary("intuition.library", 0);
  96.     GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 0);
  97.     DosBase = (struct DosLibrary *)OpenLibrary("dos.library", 0);
  98.     IconBase = (struct IconBase *)OpenLibrary("icon.library", 0);
  99.  
  100.     if ( (IntuitionBase == NULL)
  101.             || (GfxBase == NULL)
  102.             || (DosBase == NULL)
  103.             || (IconBase == NULL) )
  104.         goto MAIN_DONE;
  105.  
  106.     if (argv)
  107.         {
  108.         /* OK, we started from CLI */
  109.         if (argc > 1)
  110.             {
  111.             if (screen = OpenScreen(&NewFileIOScreen))
  112.                 {
  113.                 NewFileIOWindow.Screen = screen;
  114.                 NewFileIOWindow.Type = CUSTOMSCREEN;
  115.                 }
  116.             }
  117.         }
  118.  
  119.     window = OpenWindow(&NewFileIOWindow);
  120.  
  121.     fileio1 = GetFileIOSupport();
  122.     fileio2 = GetFileIOSupport();
  123.  
  124.     if ((window == NULL) || (fileio1 == NULL) || (fileio2 == NULL))
  125.         goto MAIN_DONE;
  126.  
  127.     SetFlag(fileio2->Flags, WBENCH_MATCH | MATCH_OBJECTTYPE);
  128.     fileio2->DiskObjectType = WBTOOL;
  129.     fileio2->ReqTitle = (UBYTE *)"- Workbench Tools and Drawers -";
  130.  
  131.     SetAPen(window->RPort, 1);
  132.     Move(window->RPort, 25, 40);
  133.     Text(window->RPort, "= Click for FileIO Requester =", 30);
  134.  
  135.     mainswitch = TRUE;
  136.     pick = 0;
  137.  
  138.     while (mainswitch)
  139.         {
  140.         WaitPort(window->UserPort);
  141.  
  142.         ioswitch = FALSE;
  143.         while (message = GetMsg(window->UserPort))
  144.             {
  145.             class = message->Class;
  146.             ReplyMsg(message);
  147.  
  148.             switch (class)
  149.                 {
  150.                 case CLOSEWINDOW:
  151.                     mainswitch = FALSE;
  152.                     break;
  153.                 case DISKINSERTED:
  154.                     /* You should clear the GOOD_FILENAMES flag whenever you
  155.                      * detect that a new disk was inserted.
  156.                      */
  157.                     ClearFlag(fileio1->Flags, GOOD_FILENAMES);
  158.                     ClearFlag(fileio2->Flags, GOOD_FILENAMES);
  159.  
  160.                     /* While I'm here, I'll demo another feature for you. */
  161.                     ToggleFlag(fileio1->Flags, USE_VOLUME_NAMES);
  162.                     ToggleFlag(fileio2->Flags, USE_VOLUME_NAMES);
  163.  
  164.                     break;
  165.                 default:
  166.                     /* If any other event occurs, bring up that old requester! */
  167.                     ioswitch = TRUE;
  168.                     break;
  169.                 }
  170.             }
  171.  
  172.         if (ioswitch)
  173.             {
  174.             if (pick == 0)
  175.                 {
  176.                 if (TestFileIO(fileio1, window))
  177.                     /* Oops, disk swapped, so restart the other */
  178.                     ClearFlag(fileio2->Flags, GOOD_FILENAMES);
  179.                 }
  180.             else
  181.                 {
  182.                 if (TestFileIO(fileio2, window))
  183.                     /* Oops, disk swapped, so restart the other */
  184.                     ClearFlag(fileio1->Flags, GOOD_FILENAMES);
  185.                 }
  186.             pick = 1 - pick;
  187.             }
  188.         }
  189.  
  190.     mainsuccess = TRUE;
  191.  
  192. MAIN_DONE:
  193.     if (NOT mainsuccess) Alert(ALERT_NO_MEMORY, NULL);
  194.  
  195.     if (fileio1) ReleaseFileIO(fileio1);
  196.     if (fileio2) ReleaseFileIO(fileio2);
  197.  
  198.     if (window) CloseWindow(window);
  199.     if (screen) CloseScreen(screen);
  200.  
  201.     if (IntuitionBase) CloseLibrary(IntuitionBase);
  202.     if (GfxBase) CloseLibrary(GfxBase);
  203.     if (DosBase) CloseLibrary(DosBase);
  204.     if (IconBase) CloseLibrary(IconBase);
  205. }
  206.  
  207.  
  208.  
  209. BOOL TestFileIO(fileio, window)
  210. struct FileIOSupport *fileio;
  211. struct Window *window;
  212. /* This guy calls GetFileIOName(), displays the file name selected by the
  213.  * user, and returns TRUE if the user swapped disks during GetFileIOName()
  214.  * (else returns FALSE)
  215.  */
  216. {
  217.     UBYTE name[80];
  218.  
  219.     if (GetFileIOName(fileio, window))
  220.         {
  221.         /* If user was positive, display the name */
  222.         CopyString(&name[0], "[");
  223.         BuildFileIOPathname(fileio, &name[1]);
  224.         ConcatString(&name[0], "]");
  225.         AlertGrunt(&name[0], window);
  226.         }
  227.  
  228.     if (FlagIsSet(fileio->Flags, DISK_HAS_CHANGED))
  229.         {
  230.         ClearFlag(fileio->Flags, DISK_HAS_CHANGED);
  231.         return(TRUE);
  232.         }
  233.     else return(FALSE);
  234. }
  235.  
  236.